package com.hiwhitley.easy.day24;

/**
 * Created by hiwhitley on 2016/10/16.
 */
public class CompareVersionNum_165 {
    public int compareVersion(String version1, String version2) {
        if (version1.equals(version2)) {
            return 0;
        }
        String[] v1 = version1.split("\\.");
        String[] v2 = version2.split("\\.");
        int len = Math.max(v1.length, v2.length);
        for (int i = 0; i < len; i++) {
            Integer value1 = i < v1.length ? Integer.parseInt(v1[i]) : 0;
            Integer value2 = i < v2.length ? Integer.parseInt(v2[i]) : 0;
            int compare = value1.compareTo(value2);
            if (compare != 0)
                return compare;
        }
        return 0;
    }

    public static void main(String[] args) {
        CompareVersionNum_165 main = new CompareVersionNum_165();
        System.out.println(main.compareVersion("01", "1"));

    }
}
